package com.orcwar.enums;

import android.util.Log;

import com.orcwar.engine.OWItem;
import com.orcwar.engine.items.OWItemBoots;
import com.orcwar.engine.items.OWItemFat;

public enum OWItemType {

	BOOTS(1, OWItemBoots.class, true, 0),
	FAT(2, OWItemFat.class, true, 0),
	BOOTS_OF_FIRE(3, OWItemBoots.class, true, 0),
	WINGS(4, OWItemBoots.class, false, 0),
	TOTEM(4, OWItemBoots.class, true, 0),
	POOP(-1, OWItemBoots.class, true, 0),
	ROTTEN_MEAT(-2, OWItemBoots.class, true, 3),
	DEATH_LINK(-3, OWItemBoots.class, true, 0),
	CURSED_DAGGER(-4, OWItemBoots.class, true, 0),
	COLOR_CHANGE(0, OWItemBoots.class, true, 0);

	private int quality;

	private Class<? extends OWItem> impl;

	private boolean stackable;

	private int maxStacks;

	private OWItemType(int quality, Class<? extends OWItem> impl,
			boolean stackable, int maxStacks) {
		this.quality = quality;
		this.impl = impl;
		this.stackable = stackable;
		this.maxStacks = maxStacks;
	}

	public int getQuality() {
		return quality;
	}

	public void setQuality(int quality) {
		this.quality = quality;
	}

	public Class<? extends OWItem> getImpl() {
		return impl;
	}

	public void setImpl(Class<? extends OWItem> impl) {
		this.impl = impl;
	}

	public boolean isStackable() {
		return stackable;
	}

	public void setStackable(boolean stackable) {
		this.stackable = stackable;
	}

	public int getMaxStacks() {
		return maxStacks;
	}

	public void setMaxStacks(int maxStacks) {
		this.maxStacks = maxStacks;
	}

	public static OWItemType getItemOfQuality(int q) {
		int correctedQuality = Math.max(-4, Math.min(q, 4));
		Log.d(OWItemType.class.getName(), "Searching an item of quality "
				+ correctedQuality);
		while (true) {
			int index = (int) (Math.random() * OWItemType.values().length);
			if (OWItemType.values()[index].quality == correctedQuality) {
				return OWItemType.values()[index];
			}
		}

	}

}
